package com.KKd.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import java.text.SimpleDateFormat;

/**
 * @author 14587
 * @date 2020/11/13 22:27
 */
public class JsonUtils {
        public static String getJson(Object object){
            return getJson(object,"yyyy-MM-dd");
        }

        public static String getJson(Object object,String format){
            ObjectMapper mapper = new ObjectMapper();
            mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false);
            SimpleDateFormat fmt = new SimpleDateFormat(format);
            mapper.setDateFormat(fmt);
            try {
                return mapper.writeValueAsString(object);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
            return null;
        }
}
